package com.company;

import java.util.Arrays;

public class Main {
    public static int uniquePathsWithObstacles(int[][] obstacleGrid){
        int m = obstacleGrid.length,
                n = obstacleGrid[0].length;
//        System.out.println(m+","+n);
//        System.out.println(Arrays.deepToString(obstacleGrid));
        for(int i=0;i<n;i++){
            System.out.println(obstacleGrid[0][i]);
            if(obstacleGrid[0][i] == 1){
                for(int j=i;j<n;j++){
                    obstacleGrid[0][j] = 0;
                }
                break;
            }
            else obstacleGrid[0][i] = 1;
        }
        for(int i=1;i<m;i++){
            if(obstacleGrid[i][0] == 1){
                for(int j=i;j<m;j++){
                    obstacleGrid[j][0] = 0;
                }
                break;
            }
            else obstacleGrid[i][0] = 1;
        }

//        System.out.println(Arrays.deepToString(obstacleGrid));
        for(int i=1;i<m;i++){
            for(int j=1;j<n;j++){
                if(obstacleGrid[i][j] == 1){
                    obstacleGrid[i][j] = 0;
                    continue;
                }
                else obstacleGrid[i][j] = obstacleGrid[i][j-1] + obstacleGrid[i-1][j];
            }
        }
        return obstacleGrid[m-1][n-1];
    }
    public static void main(String[] args) {
	// write your code here
        int [][] a = {{0,0,0}, {0,1,0}, {0,0,0}};
        System.out.println(uniquePathsWithObstacles(a));
    }
}
